﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;


using HGZP.BLL;
using HGZP.Model;
using HGZP.PLL;

namespace SZCB.admin.FoodManager
{
    public partial class AddFoodClass : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
/*            string _strAction = Request.QueryString["action"];
            string _strGuid = Request.QueryString["guid"];
            if (Session["UserId"] == null)
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>top.location.href='../login.aspx';</script>");
                return;
            }
            if (string.IsNullOrEmpty(_strAction))
                return;
            if (IsPostBack == false)
            {
                BindPublishers();
                BindBookContentClass();
                hfAction.Value = _strAction.ToLower();
                hfGuid.Value = _strGuid;
                if (_strAction == "add")
                {

                }
                else if (_strAction == "edit" && !string.IsNullOrEmpty(_strGuid))
                {
                    BindBookInfo(_strGuid);
                    cbLetter.Visible = false;
                }
                else
                    this.ClientScript.RegisterStartupScript(this.GetType(), "",
                                                            "<script>alert('参数错误');window.location.href='WorkBook_List.aspx';</script>");
            }*/


        }


        #region 绑定出版商

        /// <summary>
        /// 绑定出版商
        /// </summary>
        private void BindPublishers()
        {
       /*     CBasePublishersBLL publishersBll = new CBasePublishersBLL();
            ddlPublishers.DataSource = publishersBll.F02_SelectHaveWhere(string.Empty);
            ddlPublishers.DataTextField = publishersBll.sName;
            ddlPublishers.DataValueField = publishersBll.sGuid;
            ddlPublishers.DataBind();*/
        }

        #endregion

        #region 提交按钮

        /// <summary>
        /// 提交按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            CsFoodClassBLL foodbll = new CsFoodClassBLL();
            DataTable dt = foodbll.F02_SelectHaveWhere("sName = '" + txtName.Text + "'");
            if (dt.Rows.Count > 0)
            {
                string strErrmessage = "该食品大类已添加";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }
            CsFoodClass foodclass = new CsFoodClass();
            foodclass.sGuid = MyFunction.GetNewGuid();
            foodclass.sName = txtName.Text;
            foodclass.dCreateDate = DateTime.Now;
            if ( ! foodbll.F_Insert(foodclass))
            {
                string strErrmessage = "添加食品大类失败";
                Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + strErrmessage + "');</script>");
                return;
            }

        }
        #endregion


    }
}